#ifdef _FULLPROGRAM

#include "ksymtbl.h"
#include "kerror.h"

void SymbolTable::AddSymbol(const k_string &ident, KType type, k_uint ln)
{
	symtbl_t::iterator it = this->table.find(ident);

	if (it != this->table.end())
		throw KCompileError(KCE_DUPLICATED_VAR, ln);

	this->table[ident] = type;
}

void SymbolTable::RemoveSymbol(const k_string &ident, k_uint ln)
{
	symtbl_t::iterator it = this->table.find(ident);

	if (it == this->table.end())
		throw KCompileError(KCE_UNDECLARED_VAR, ln);

	this->table.erase(it);
}

void SymbolTable::HasSymbol(const k_string &ident, k_uint ln)
{
	symtbl_t::iterator it = this->table.find(ident);

	if (it == this->table.end())
		throw KCompileError(KCE_UNDECLARED_VAR, ln);
}

void SymbolTable::CleanUp()
{
	this->table.clear();
}

KType SymbolTable::GetSymbolType(const k_string &ident, k_uint ln) const
{
	symtbl_t::const_iterator it = this->table.find(ident);

	if (it == this->table.end())
		throw KCompileError(KCE_UNDECLARED_VAR, ln);

	return it->second;
}

#endif //_FULLPROGRAM
